package Persondata;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.hibernate.Session;

import db.HibernateHelper;

public class PersonNeu extends WebPage {
			
	public PersonNeu() {
		// Default values
		Person p = new Person("Testnachname", "Testvorname", 99, "Testjob");
		final CompoundPropertyModel<Person> model = new CompoundPropertyModel<Person>(p);
		
		// Panel einfügen
		add(new PersonFormPanel("neuePersonFormular", model, "Person einfügen") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmitModelHandle(IModel<Person> model) {
				Session session = HibernateHelper.getSessionFactory().getCurrentSession();
				session.beginTransaction();
				session.save(model.getObject());
				session.getTransaction().commit();
//				session.close();
				this.setResponsePage(PersonWeb.class);
			}
		});
		
	}

	
	

}
